﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Bootstrap.MVC.Utils;

namespace Bootstrap.MVC.Widgets
{
    public abstract class BuilderBase<TModel, TBuilder>
        where TModel : IModelBase
        where TBuilder : class
    {

        protected TModel Model;
        
        protected BuilderBase(TModel component)
        {
            Model = component;
        }

        #region Public Methods
        public virtual TBuilder Id(string id)
        {
            Guard.IsNotNullOrEmpty(id, "id");
            Model.Attr("id", id);
            return this as TBuilder;
        }

        public virtual TBuilder Name(string name)
        {
            Guard.IsNotNullOrEmpty(name, "name");
            Model.Attr("name", name);
            return this as TBuilder;
        }

        public virtual TBuilder Css(string css, bool replacement= false) 
        {
            Guard.IsNotNullOrEmpty(css, "css");
            css = replacement ? Model.Attr("class").ToString().AppendWithSemicolon(css) : css;
            Model.Attr("class", css);
            return this as TBuilder;
        }

        public virtual TBuilder Attr(string name,object value)
        {
            Guard.IsNotNullOrEmpty(name, "name");
            Model.Attr(name, value);
            return this as TBuilder;
        }
        #endregion Public Methods
    }
}
